/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-08-27 17:06:56
 * @LastEditors: 商晓彬
 * @LastEditTime: 2021-12-22 15:04:53
 */
import { LazyLoadEvent } from 'primeng/api';
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { MessageService } from '@abp/message/message.service';
import { StoreFunctionsServiceProxy, StorePutServiceProxy, StorePutModelContentDto, StoreInfoServiceProxy ,StoreDropListOutDto} from '@shared/service-proxies/service-proxies';
import { finalize } from 'rxjs/operators';
import { SupplementaryCertificateComponent } from './supplementary-certificate/supplementary-certificate.component';
import { CertificateMsgComponent } from './certificate-msg/certificate-msg.component';
import { ReleaseMsgComponent } from './release-msg/release-msg.component';
import { ManualMsgComponent } from './manual-msg/manual-msg.component';
import { AddShowResumeComponent } from '../warehousing/add-show-resume/add-show-resume.component';
import { MatchingWatchComponent } from './matching-watch/matching-watch.component';

@Component({
    selector: 'app-warehouse-msg',
    templateUrl: './warehouse-msg.component.html',
    styleUrls: ['./warehouse-msg.component.less']
})
export class WarehouseMsgComponent extends AppComponentBase {
    @ViewChild('AddShowResumeComponent') AddShowResumeComponent: AddShowResumeComponent;
    @ViewChild('MatchingWatchComponent') MatchingWatchComponent: MatchingWatchComponent;
    @ViewChild('SupplementaryCertificateComponent') SupplementaryCertificateComponent: SupplementaryCertificateComponent;
    @ViewChild('CertificateMsgComponent') CertificateMsgComponent: CertificateMsgComponent;
    @ViewChild('ReleaseMsgComponent') ReleaseMsgComponent: ReleaseMsgComponent;
    @ViewChild('ManualMsgComponent') ManualMsgComponent: ManualMsgComponent;
    @ViewChild('paginator') paginator: Paginator;
    @ViewChild('dataTable') dataTable: Table;
    stroeName = undefined;
    stroeNameOptions = [];
    productDrawingNo = undefined;
    drawingNoOptions = [];
    productName = undefined;
    productNameOptions = [];
    module = undefined;
    moduleOptions = [];
    materialsType = undefined;
    materialsTypeOptions = undefined;
    materialsNode = undefined;
    materialsNodeOptions = [];
    materialsAttribute = undefined;
    materialsAttributeOptions = [
        {
            label: '正常品',
            value: 0
        }, {
            label: '隔离品',
            value: 1
        }, {
            label: '返修品',
            value: 2
        }, {
            label: '报废品',
            value: 3
        }
    ];
    qualifiedNumber = undefined;
    qualifiedNumberOptions = [];
    releaseOrder = undefined;
    releaseOrderOptions = [];
    productCode = undefined;
    productCodeOptions = [];
    sendTime = undefined;
    sendTimeOptions = [];
    rowdata: any;
    title = undefined;
    typeStatus: any;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _storeFunctionsServiceProxy: StoreFunctionsServiceProxy,
        private _storePutServiceProxy: StorePutServiceProxy,
        private _storeInfoServiceProxy: StoreInfoServiceProxy,
    ) {
        super(injector);
    }
    openUrl() {
        window.open('http://10.20.253.4:8057/#/app/material/index');
    }
    reset() {
        this.stroeName = undefined;
        this.productDrawingNo = undefined;
        this.productName = undefined;
        this.module = undefined;
        this.materialsType = undefined;
        this.materialsTypeOptions = undefined;
        this.materialsNode = undefined;
        this.materialsAttribute = undefined;
        this.qualifiedNumber = undefined;
        this.releaseOrder = undefined;
        this.productCode = undefined;
        this.sendTime = undefined;
    }
    lookResume(row) {
        this.rowdata = row;
        setTimeout(() => {
            this.AddShowResumeComponent.show();
            this.AddShowResumeComponent.getTableList();
        }, 10);
    }
    ptWatch(row) {
        this.rowdata = row;
        setTimeout(() => {
            this.MatchingWatchComponent.show();
            this.MatchingWatchComponent.getTableList();
        }, 10);
    }
    watch(row, type) {
        this.typeStatus = type
        this.rowdata = row;
        if (row.warehousMethod == 0) {
            //合格证
            this.title = '合格证信息查看';
            setTimeout(() => {
                this.CertificateMsgComponent.show();
            }, 10);
        } else if (row.warehousMethod == 1) {
            //放行单
            this.title = '放行单信息查看';
            setTimeout(() => {
                this.ReleaseMsgComponent.show();
            }, 10);
        } else if (row.warehousMethod == 2) {
            //手动合格
            this.title = '合格证手工入库信息查看';
            setTimeout(() => {
                this.ManualMsgComponent.show();
            }, 10);
        }
    }
    update(row, type) {
        this.typeStatus = type
        this.rowdata = row;
        if (row.warehousMethod == 0) {
            //合格证
            this.title = '合格证信息修改';
            setTimeout(() => {
                this.CertificateMsgComponent.show();
            }, 10);
        } else if (row.warehousMethod == 1) {
            //放行单
            this.title = '放行单信息修改';
            setTimeout(() => {
                this.ReleaseMsgComponent.show();
            }, 10);
        } else if (row.warehousMethod == 2) {
            //手动合格
            this.title = '合格证手工入库信息修改';
            setTimeout(() => {
                this.ManualMsgComponent.show();
            }, 10);
        }
    }
    ex(row, type) {
        this.rowdata = row;
        this.typeStatus = type

        this.title = '产品隔离';
        if (row.warehousMethod == 0) {
            //合格证
            setTimeout(() => {
                this.CertificateMsgComponent.show();
            }, 10);
        } else if (row.warehousMethod == 1) {
            //放行单
            setTimeout(() => {
                this.ReleaseMsgComponent.show();
            }, 10);
        } else if (row.warehousMethod == 2) {
            //手动合格
            setTimeout(() => {
                this.ManualMsgComponent.show();
            }, 10);
        }
    }
    add() {
        setTimeout(() => {
            this.SupplementaryCertificateComponent.show();
        }, 10);
    }
    ngOnInit() {
        //仓库名称
        this._storeFunctionsServiceProxy.getStoreDropList(
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.stroeNameOptions = [];
                this.stroeNameOptions = result;
            });
        //产品图号
        this._storePutServiceProxy.getProductDrawingNoList(
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.drawingNoOptions = [];
                for (const item of result) {
                    let data = { label: undefined, value: undefined };
                    data.label = item;
                    data.value = item;
                    this.drawingNoOptions.push(data);
                }
            });
        //产品名称
        this._storeFunctionsServiceProxy.getProductNameDropList(
            this.productDrawingNo
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.productNameOptions = [];
                for (const item of result) {
                    let data = { label: undefined, value: undefined };
                    data.label = item;
                    data.value = item;
                    this.productNameOptions.push(data);
                }
            });
        //物料类别
        this._storeFunctionsServiceProxy.getMaterialsTypeDropList(
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.materialsNodeOptions = [];
                this.materialsNodeOptions = result;
            });
        //合格证下拉
        this._storePutServiceProxy.getQualifiedNumberList(
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.qualifiedNumberOptions = [];
                for (const item of result) {
                    let data = { label: undefined, value: undefined };
                    data.label = item;
                    data.value = item;
                    this.qualifiedNumberOptions.push(data);
                }
            });
        //放行单下拉
        this._storeFunctionsServiceProxy.getReleaseOrderList(
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.releaseOrderOptions = [];
                for (const item of result) {
                    let data = { label: undefined, value: undefined };
                    data.label = item;
                    data.value = item;
                    this.releaseOrderOptions.push(data);
                }
            });
        //型号下拉
        this._storeFunctionsServiceProxy.getRocketModeDropList(
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.productCodeOptions = [];
                this.productCodeOptions = result;
            });
    }
    getSendTime(event) {
         //发次下拉
        let input = new StoreDropListOutDto();
        if (this.productCode != undefined) {
            input.value = this.productCode;
        }
        let data = [];
        data.push(input);
        this._storeFunctionsServiceProxy.getRocketLotNoDropList(
            data
            ).pipe(finalize(() => { }))
                .subscribe(result => {
                    this.sendTimeOptions = [];
                    this.sendTimeOptions = result;
                });
    }
    getProductNameDropListEv(event) {
        //产品名称
        this._storeFunctionsServiceProxy.getProductNameDropList(
            event.value
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.productNameOptions = [];
                for (const item of result) {
                    let data = { label: undefined, value: undefined };
                    data.label = item;
                    data.value = item;
                    this.productNameOptions.push(data);
                }
            });
         //规格
         this._storeFunctionsServiceProxy.getMaterialsContentsModelList(
            event.value
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.moduleOptions = [];
                this.moduleOptions = result;
            });
    }

    onChange(event) {
        //物料细类
        this._storeFunctionsServiceProxy.getSegmentationMaterialsTypeDropList(
            event.value
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.materialsTypeOptions = [];
                this.materialsTypeOptions = result;
            });

    }
    resert() {
        this.stroeName = undefined;
        this.productDrawingNo = undefined;
        this.productName = undefined;
        this.module = undefined;
        this.materialsType = undefined;
        this.materialsNode = undefined;
        this.materialsNodeOptions = [];
        this.materialsAttribute = undefined;
        this.qualifiedNumber = undefined;
        this.releaseOrder = undefined;
        this.productCode = undefined;
        this.sendTime = undefined;
        //产品名称
        this._storeFunctionsServiceProxy.getProductNameDropList(
            this.productDrawingNo
        ).pipe(finalize(() => { }))
            .subscribe(result => {
                this.productNameOptions = [];
                this.productNameOptions = result;
            });
    }
    enum(value) {
        switch (value) {
            case 0:

                return '正常品';
            case 1:

                return '隔离品';
            case 2:

                return '返修品';
            case 3:

                return '报废品';
            case 4:

                return '返修正常品';
            default:
                return '';
        }
    }
    getTableList(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        this._storeInfoServiceProxy.getStoreInfoList(
            this.stroeName,
            this.productDrawingNo,
            this.productName,
            this.module,
            this.materialsType,
            this.materialsNode,
            this.materialsAttribute,
            this.qualifiedNumber,
            this.releaseOrder,
            this.productCode,
            this.sendTime,
            this.primengTableHelper.getSorting(this.dataTable),
            this.primengTableHelper.getMaxResultCount(this.paginator, event),
            this.primengTableHelper.getSkipCount(this.paginator, event)
        ).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
            this.primengTableHelper.totalRecordsCount = result.totalCount;
            this.primengTableHelper.records = result.items;
            this.primengTableHelper.hideLoadingIndicator();
        });
    }
}
